package PhoneLog.PhoneLog2;
/**
 * 自定义分区
 */

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Partitioner;
//Map端的输出类型
public class phonePartition extends Partitioner <Text,FlowBean>{
    //重写getPartition()方法
    @Override
    public int getPartition(Text text, FlowBean flowBean, int reduceTaskNum) {
        //1.获取key值-->Text(手机号)
        String phoneNum = text.toString();
        int partition=3;
       /* 13660577991 湖南
        13760778710	  河南
        13826544101   浙江*/
       //2.获取手机号前三位([0,3))(分为3个区要与reduceTask任务一致)
        String preNum= phoneNum.substring(0, 3);
        if(preNum.equals("136")){
            partition=0;
        }else if(preNum.equals("137")){
            partition=1;

        }else if (preNum.equals("138")){
            partition=2;
        }


        return partition;
    }
}
